<html>
<head><meta charset="utf-8"><title>Undefined symbols in staticlib compiled to wasm32? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Undefined.20symbols.20in.20staticlib.20compiled.20to.20wasm32.3F.html">Undefined symbols in staticlib compiled to wasm32?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205484844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Undefined%20symbols%20in%20staticlib%20compiled%20to%20wasm32%3F/near/205484844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Undefined.20symbols.20in.20staticlib.20compiled.20to.20wasm32.3F.html#205484844">(Jul 30 2020 at 14:26)</a>:</h4>
<p>According to <a href="https://doc.rust-lang.org/reference/linkage.html">the reference</a> "staticlib" should include dependencies of the crate and allow linking the crate with non-Rust programs. In <a href="https://github.com/osa1/wasm_test/tree/master/rs_nostd_core_lib_2">https://github.com/osa1/wasm_test/tree/master/rs_nostd_core_lib_2</a> I have an example project setup where I build a "staticlib" crate, and link it with a C library into a shared library, targeting wasm32-unknown-emscripten. I already do this stuff using C and Rust and it works. However the problem when I target wasm32 is I get undefined Rust 'core' symbols, which are compiled to <a href="https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md#imports">"GOT.func" imports</a>, as a result the final Wasm library is not really linkable.</p>
<p>I'm not sure that this is a bug in rustc, maybe it's a bug in LLVM (code generator parts), or in wasm-ld, or maybe I'm doing something wrong. I'm wondering how to debug this. The question basically is why do I get those "GOT.func" imports.</p>
<p>To reproduce make sure you have llvm-10 and xargo installed and have nightly Rust, and run <code>./build.sh</code>. You'll see a file "libfinal.wat". If you open it you'll see this import:</p>
<div class="codehilite"><pre><span></span><code>(import &quot;GOT.func&quot; &quot;_ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h9ba9fea9cadf7bd5E&quot; (global (;3;) (mut i32)))
</code></pre></div>


<p>This basically means there's a Rust function not defined in this shared library file, which seems wrong as the crate is compiled to a "staticlib" which should include all dependencies.</p>
<p>Does anyone have any ideas? Thanks.</p>



<a name="205770820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Undefined%20symbols%20in%20staticlib%20compiled%20to%20wasm32%3F/near/205770820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Undefined.20symbols.20in.20staticlib.20compiled.20to.20wasm32.3F.html#205770820">(Aug 03 2020 at 08:33)</a>:</h4>
<p>I moved this to Rust issue tracker: <a href="https://github.com/rust-lang/rust/issues/75089">https://github.com/rust-lang/rust/issues/75089</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>